"use strict";
cc._RF.push(module, '2536cZy+uxCRpneBlpIejnR', 'HallCarTotalView');
// scripts/HallCarTotalView.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("GlobalUserData"),
    s = t("BroadCastMessage"),
    l = t("HallCarView"),
    c = t("HallConstant"),
    d = t("Util"),
    h = t("HallConstant"),
    p = t("Hint"),
    u = t("Common"),
    f = cc._decorator,
    m = f.ccclass,
    _ = f.property,
    y = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.btn_prev = null, e.btn_next = null, e.arrNode_carItem = new Array(), e.arrNode_car = new Array(), e.arrBtn_assembly = new Array(), e.arrCarView = [], e._hallControl = null, e.arrCarPos = [], e.bCurShowHall = !1, e.bCurShowAssembly = !1, e.supercar_guide = null, e.curAssemblyIndex = -1, e;
  }

  return n(e, t), e.prototype.onLoad = function () {
    this.onShowBtn(!1);
  }, e.prototype.init = function (t) {
    this._hallControl = t, this.btncar_00 = this.node.getChildByName("btncar_00"), this.scheduleOnce(function () {
      this.delayInit();
    }, 0), console.log("车位：" + r["default"].curEquipBody.length);

    for (var e = 0; e < r["default"].curEquipBody.length; e++) {
      var o = r["default"].curEquipBody[e];
      console.log(o);
    }
  }, e.prototype.delayInit = function () {
    for (var t = this, e = 0; e < 2; e++) {
      (o = cc.instantiate(this.btncar_00)).x = 0 + 325 * e, o.parent = this.node;
    }

    for (e = 0; e < this.node.childrenCount; e++) {
      var o;
      null != (o = this.node.children[e]).getChildByName("car_00") && (this.arrNode_car.push(o), this.arrNode_carItem.push(o.getChildByName("car_00")), this.arrBtn_assembly.push(o.getChildByName("btn_assemble")), o.getChildByName("btn_assemble").getComponent(cc.Button).clickEvents[0].customEventData = this.arrBtn_assembly.indexOf(o.getChildByName("btn_assemble")).toString());
    }

    for (e = 0; e < this.arrNode_car.length; e++) {
      this.arrCarPos.push(this.arrNode_car[e].position);
    }

    for (e = 0; e < r["default"].nEquipMax; e++) {
      this.arrNode_carItem[e].scale = .8;
      var i = this.arrNode_carItem[e].getComponent(l["default"]);
      cc.log(e + "," + r["default"].swapCarIndex), i.init(this._hallControl, e), this.arrCarView.push(i);
    }

    this.scheduleOnce(function () {
      4 != r["default"].nTotalGame || r["default"].upgradeState || t._hallControl.guide_click(t.arrNode_car[0].getChildByName("btn_assemble"), -1);
    }, .5), -1 != r["default"].swapCarIndex && this.setSuperCarIndex("0", r["default"].swapCarIndex);
  }, e.prototype.onGuideAction = function () {
    r["default"].nGuideStep != c.Guide_Step.UnlockCar_2 && r["default"].nGuideStep != c.Guide_Step.Assembly_In_2 || this._hallControl.guide_click(this.arrNode_car[1].getChildByName("btn_assemble"), -1), r["default"].nGuideStep == c.Guide_Step.Assembly_In && this._hallControl.guide_click(this.arrNode_car[0].getChildByName("btn_assemble"), -1);
  }, e.prototype.setCarItemToAssemblyView = function (t) {
    for (var e = 0; e < this.arrNode_carItem.length; e++) {
      this.arrNode_carItem[e].getComponent(l["default"]).setAssemblyView(t);
    }
  }, e.prototype.onShowHall = function () {
    this.onShowBtn(!1), this.bCurShowHall = !0, this.bCurShowAssembly = !1;

    for (var t = 0; t < this.arrCarView.length; t++) {
      this.arrCarView[t].onShowHall();
    }

    for (t = 0; t < this.arrNode_car.length; t++) {
      t == this.curAssemblyIndex ? this.playAnim(this.arrCarPos[t]) : (this.arrNode_car[t].active = !0, this.arrNode_car[t].position = this.arrCarPos[t]);
    }

    for (t = 0; t < this.arrBtn_assembly.length; t++) {
      this.arrBtn_assembly[t].active = !0;
    }
  }, e.prototype.setSuperCar = function () {
    this.onBtnSuperChariotGuide();
  }, e.prototype.setFreeCar = function () {
    var t = this;
    this.playAudio(h.Audio_ID.btn_click), cc.resources.load("prefab/supercar_guide", cc.Prefab, function (e, o) {
      var i = cc.instantiate(o);
      t.supercar_guide = i, null != r["default"].popup ? r["default"].popup.active = !1 : (r["default"].popup = t.supercar_guide, r["default"].popup.name = "supercar_guide"), cc.find("Canvas").addChild(i), cc.find("Canvas").getChildByName("gift_frame").active = !1;

      for (var n = 0; n < t.arrBtn_assembly.length; n++) {
        var a = t.arrBtn_assembly[n].getComponent(cc.Button);
        a.clickEvents[0].handler = "setFreeCarIndex", a.clickEvents[0].customEventData = n.toString();
      }
    });
  }, e.prototype.setFreeCarIndex = function (t, e) {
    var o = Number(e);

    if (r["default"].curEquipBody[o]) {
      r["default"].saveOwnCarBodyData(!0, r["default"].freeCarData.arrBody[0]), r["default"].saveOwnWheelData(!0, r["default"].freeCarData.arrWheel[0]), r["default"].saveOwnWheelData(!0, r["default"].freeCarData.arrWheel[1]), r["default"].saveOwnWeaponData(!0, r["default"].freeCarData.arrWeapon[0]), r["default"].saveOwnToolsData(!0, r["default"].freeCarData.arrTools[0]), r["default"].saveEquipBodyData(o, r["default"].freeCarData.arrBody[0].uid), r["default"].saveEquipWheelData(o, 0, r["default"].freeCarData.arrWheel[0].uid), r["default"].saveEquipWheelData(o, 1, r["default"].freeCarData.arrWheel[1].uid), r["default"].saveEquipWeaponData(o, 0, r["default"].freeCarData.arrWeapon[0].uid), r["default"].saveEquipToolsData(o, 0, r["default"].freeCarData.arrTools[0].uid), null != r["default"].popup && ("supercar_guide" == r["default"].popup.name ? r["default"].popup = null : r["default"].popup.active = !0), this.arrNode_carItem[o].getComponent(l["default"]).refreshView(), this.supercar_guide && this.supercar_guide.destroy();

      for (var i = 0; i < this.arrBtn_assembly.length; i++) {
        this.arrBtn_assembly[i].getComponent(cc.Button).clickEvents[0].handler = "onBtnAssembly";
      }
    } else p["default"].show("车位锁定");
  }, e.prototype.onBtnSuperChariotGuide = function () {
    var t = this;
    this.playAudio(h.Audio_ID.btn_click), cc.resources.load("prefab/supercar_guide", cc.Prefab, function (e, o) {
      var i = cc.instantiate(o);
      t.supercar_guide = i, null != r["default"].popup ? r["default"].popup.active = !1 : (r["default"].popup = t.supercar_guide, r["default"].popup.name = "supercar_guide"), cc.find("Canvas").addChild(i), cc.find("Canvas").getChildByName("gift_frame").active = !1;

      for (var n = 0; n < t.arrBtn_assembly.length; n++) {
        var a = t.arrBtn_assembly[n].getComponent(cc.Button);
        a.clickEvents[0].handler = "setSuperCarIndex", a.clickEvents[0].customEventData = n.toString();
      }
    });
  }, e.prototype.setSuperCarIndex = function (t, e) {
    var o = Number(e);
    null != r["default"].popup && ("supercar_guide" == r["default"].popup.name ? r["default"].popup = null : r["default"].popup.active = !0), d.Util.superCarSwapData(!0, o), this.arrNode_carItem[o].getComponent(l["default"]).refreshView(!0), this.supercar_guide && this.supercar_guide.destroy(), cc.find("Canvas").getChildByName("gift_frame").active = !0;

    for (var i = 0; i < this.arrBtn_assembly.length; i++) {
      this.arrBtn_assembly[i].getComponent(cc.Button).clickEvents[0].handler = "setCarHint";
    }
  }, e.prototype.setCarHint = function () {
    p["default"].show("已装配试玩车辆，不能改装，请开始游戏。");
  }, e.prototype.onShowAssembly = function () {
    this.bCurShowHall = !1, this.bCurShowAssembly = !0, cc.log("curAssemblyIndex：" + this.curAssemblyIndex), this.arrCarView[this.curAssemblyIndex].onShowAssembly();

    for (var t = 0; t < this.arrBtn_assembly.length; t++) {
      this.arrBtn_assembly[t].active = !1;
    }

    this.onShowBtn(!0);
  }, e.prototype.getCurAssemblyItem = function (t) {
    return this.arrCarView[this.curAssemblyIndex].getAssemblyItem(t);
  }, e.prototype.onBtnAssembly = function (t, e) {
    if (this.bCurShowHall && -1 == r["default"].swapCarIndex) {
      var o = Number(e);
      if (this.arrCarView[o].IsLock) return 1 == o && u["default"].getIns().logEvent(u.LogEventType.Car2Btn, "", 2), void this.arrCarView[o].showUnlockView();
      1 == r["default"].nTotalGame && 1 == o && u["default"].getIns().logEvent(u.LogEventType.Car2refit, "", 2), r["default"].popup = this.arrCarView[o].node, r["default"].hallCarView = this.arrCarView[o], this._hallControl.reset_Guide(), this.curAssemblyIndex = o;

      for (var i = 0; i < this.arrNode_car.length; i++) {
        i == o ? (this.arrNode_car[i].active = !0, this.playAnim(cc.v3(0, 0, 0))) : this.arrNode_car[i].active = !1;
      }

      this._hallControl.onBtnAssembly(o);
    }
  }, e.prototype.playAnim = function (t) {
    cc.tween(this.arrNode_car[this.curAssemblyIndex]).to(1, {
      position: t
    }).start();
  }, e.prototype.onShowNextCar = function () {
    for (var t = 0; t < this.arrNode_car.length; t++) {
      t == this.curAssemblyIndex ? (this.arrNode_car[t].active = !0, this.arrNode_car[t].position = cc.v3(0, 0, 0)) : this.arrNode_car[t].active = !1;
    }

    this.arrCarView[this.curAssemblyIndex].onShowAssembly(), this._hallControl.onShowNextCar(this.curAssemblyIndex);
  }, e.prototype.onBtnPrev = function () {
    this.playAudio(c.Audio_ID.btn_click), this.btn_prev.node.active = !1, this.curAssemblyIndex--, this.curAssemblyIndex < 0 ? this.curAssemblyIndex = 0 : this.onShowNextCar(), this.onShowBtn(!0);
  }, e.prototype.onBtnNext = function () {
    this.playAudio(c.Audio_ID.btn_click), this.btn_next.node.active = !1, this.curAssemblyIndex++, this.curAssemblyIndex >= c.Car_Assembly_Max ? this.curAssemblyIndex = c.Car_Assembly_Max - 1 : this.onShowNextCar(), this.onShowBtn(!0);
  }, e.prototype.onShowBtn = function () {
    this.btn_next.node.active = !1, this.btn_prev.node.active = !1;
  }, e.prototype.onEquipCarItem = function (t, e, o, i) {
    this.arrCarView[this.curAssemblyIndex].onEquipCarItem(t, e, o, i);
  }, e.prototype.showCarWheelFrame = function (t) {
    this.arrCarView[this.curAssemblyIndex].showCarWheelFrame(t);
  }, e.prototype.showCarWeaponFrame = function (t) {
    this.arrCarView[this.curAssemblyIndex].showCarWeaponFrame(t);
  }, e.prototype.showCarToolsFrame = function (t) {
    this.arrCarView[this.curAssemblyIndex].showCarToolsFrame(t);
  }, e.prototype.onLightActivie = function (t) {
    this.arrCarView[this.curAssemblyIndex].onLightActivie(t);
  }, e.prototype.playAudio = function (t) {
    this._hallControl ? this._hallControl.playAudio(t) : s["default"].getInstance().SendMessage(c.Broadcast_Func.Audio, t);
  }, a([_(cc.Button)], e.prototype, "btn_prev", void 0), a([_(cc.Button)], e.prototype, "btn_next", void 0), a([m], e);
}(cc.Component);

o["default"] = y;

cc._RF.pop();